var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Hts = require("Hts");
var $2WeChatConstant = require("WeChatConstant");
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var $2ShopItem = require("ShopItem");
var $2BundleManager = require("BundleManager");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2MyUtils = require("MyUtils");
var $2MenuUI = require("MenuUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_ShopUI = /* */function (_cc$Component66) {
  babel_inherits(y, _cc$Component66);
  var _super82 = babel_createSuper(y);
  function y() {
    var _this190;
    babel_classCallCheck(this, y);
    _this190 = _super82.apply(this, arguments);
    _this190.list = null;
    _this190.boughtItem = [];
    return _this190;
  }
  babel_createClass(y, [{
    key: "onLoad",
    value: function onLoad() {
      Adv_skd.default.instance.hideAllAdv();
      Adv_skd.default.instance.showInterstitialAd();
      Adv_skd.default.instance.showGridAdRight();
      Adv_skd.default.instance.showGridAdLeft();

      var _this191 = this;
      $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.refreshShop);
      this.initPanel();
      this.refreshVideoBtn();
      this.refreshTime();
      this.initPlatform();
      this.schedule(function () {
        _this191.refreshTime();
      }, 1);
      $2TaSdk.default.instance.postEvent("System", {
        system: "商店"
      });
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.WeChat:
          $2ADManager.default.instance.showNative(2);
          $2ADManager.default.instance.showNative(3);
          $2ADManager.default.instance.showNative(1);
          $2ADManager.default.instance.hideNative(0);
      }
    }
  }, {
    key: "refreshTime",
    value: function refreshTime() {
      if ($2UserDataManager.default.instance.getHour() != $2UserDataManager.default.instance.shopHour) {
        $2UserDataManager.default.instance.getShopInfo();
        this.refreshPanel();
      }
      var e = new Date();
      var t = "0" + ($2UserDataManager.default.instance.shopHour + 7 - e.getHours()).toString();
      var a = 59 - e.getMinutes();
      a < 10 && (a = "0" + a.toString());
      var n = 59 - e.getSeconds();
      n < 10 && (n = "0" + n.toString());
      this.node.getChildByName("Bg").getChildByName("Time").getComponentInChildren(cc.Label).string = "刷新倒计时： " + t + "：" + a + "：" + n;
    }
  }, {
    key: "initPanel",
    value: function initPanel() {
      for (var _e101 = 0; _e101 < 8; _e101++) {
        var _t65 = $2UserDataManager.default.instance.shopInfo[_e101];
        if (_t65.bought) {
          this.boughtItem.push(_t65);
        } else {
          var _a54 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/ShopItem"));
          _a54.getComponent($2ShopItem.default).init(_t65, _e101);
          _a54.parent = this.list;
        }
      }
      for (var _e102 = 0; _e102 < this.boughtItem.length; _e102++) {
        var _t66 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/ShopItem"));
        _t66.getComponent($2ShopItem.default).init(this.boughtItem[_e102], _e102);
        _t66.parent = this.list;
      }
    }
  }, {
    key: "refreshVideoBtn",
    value: function refreshVideoBtn() {
      this.node.getChildByName("VideoBtn").getComponentInChildren(cc.Label).string = "立即刷新(" + $2UserDataManager.default.instance.shopRefreshTimes + "/5)";
    }
  }, {
    key: "refreshPanel",
    value: function refreshPanel() {
      for (var _e103 = 0; _e103 < 8; _e103++) {
        var _t67 = $2UserDataManager.default.instance.shopInfo[_e103];
        var _a55 = this.list.children[_e103];
        _a55.getComponent($2ShopItem.default).init(_t67, _e103);
        _a55.parent = this.list;
      }
    }
  }, {
    key: "onClickRefreshBtn",
    value: function onClickRefreshBtn() {
      var _this192 = this;
      if ($2UserDataManager.default.instance.shopRefreshTimes >= 5) {
        $2UIManager.default.instance.showToast("今日刷新次数已达上限！");
        return void $2Hts.default.instance.eventReport("刷新商店达上线刷新失败");
      }
      $2TaSdk.default.instance.AdsButtonClick($2TaSdk.VideoIndex.refreshShop);
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          $2UserDataManager.default.instance.shopRefreshTimes++;
          $2UserDataManager.default.instance.getShopInfo();
          _this192.refreshPanel();
          _this192.refreshVideoBtn();
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "onClickCloseBtn",
    value: function onClickCloseBtn() {
      Adv_skd.default.instance.hideAllAdv();

      $2UIManager.default.instance.closeUI("ShopUI");
      $2UIManager.default.instance.uiList.MenuUI.getComponent($2MenuUI.default).showNode();
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
        $2MyUtils.MyUtils.probability($2WeChatConstant.default.mainInster) && $2ADManager.default.instance.showInsert();
        $2ADManager.default.instance.hideNative(2);
        $2ADManager.default.instance.hideNative(3);
        $2ADManager.default.instance.hideNative(1);
        $2ADManager.default.instance.showNative(0);
      }
    }
  }]);
  return y;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_ShopUI.prototype, "list", undefined);
def_ShopUI = cc__decorate([ccp_ccclass], def_ShopUI);
exports.default = def_ShopUI;